package org.geekbang.thinking.in.spring.ioc.overview.dependency.lookup;

import org.geekbang.thinking.in.spring.ioc.overview.domain.User;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

import java.util.Map;

/**
 * annocation IoC
 *
 * @author liucheng
 * @since 0.1 2021-01-10 8:49 下午
 **/
public class AnnotationApplicationContextAsIoCContainerDemo {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(AnnotationApplicationContextAsIoCContainerDemo.class);
        applicationContext.refresh();

        Map<String, User> beans = applicationContext.getBeansOfType(User.class);
        System.out.println(beans);


    }

    @Bean
    public User user() {
        User user = new User();
        user.setId(1L);
        user.setName("小马哥annotation");
        return user;
    }
}
